package web.dao.Impl;

import web.bean.XiaoQu;
import web.dao.XiaoQuDao;
import web.utils.DBUtil;

import java.util.List;

public class XiaoQuDaoImpl implements XiaoQuDao {
    @Override
    public List<XiaoQu>  findInfo(Integer limitParams1,Integer limitParams2, String startTime, String endTime, String name) {
        return DBUtil.findByWhere(XiaoQu.class,"addtime>=? and addtime<=?  and xiaoqumingcheng like ? limit ?,?",startTime,endTime,"%"+name+"%",limitParams1,limitParams2);
    }

    @Override
    public int count(String startTime, String endTime, String name) {
        return DBUtil.findByWhere(XiaoQu.class,"addtime>=? and addtime<=?  and xiaoqumingcheng like ? ",startTime,endTime,"%"+name+"%").size();
    }

    @Override
    public int add(XiaoQu xiaoQu) {
        return DBUtil.insert(xiaoQu);
    }

    @Override
    public int del(Integer[] deleteId) {
        String where="id in (";
        for (int i = 0; i < deleteId.length; i++) {
            where=where+"?";
            if (i!=deleteId.length-1){
                where=where+",";
            }else {
                where=where+")";
            }
        }
        return DBUtil.delete(XiaoQu.class,where,deleteId);
    }

    @Override
    public int editInfo(XiaoQu xiaoQu) {
        return DBUtil.updateSelective(xiaoQu,"id=?",xiaoQu.getId());
    }

    @Override
    public XiaoQu findXiaoQuById(Integer id) {
        return DBUtil.findOneByWhere(XiaoQu.class,"id=?",id);
    }

    @Override
    public List<XiaoQu> findNameAll() {
        return DBUtil.findAll(XiaoQu.class);
    }

    @Override
    public XiaoQu findIdByName(String name) {
        return DBUtil.findOneByWhere(XiaoQu.class,"name=?","%"+name+"%");
    }
}
